/**
 * 
 */
package com.zxc.redis.Semaphore;

import java.util.concurrent.TimeUnit;

import org.redisson.Redisson;
import org.redisson.api.RSemaphore;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;

/**
 * @author Administrator
 *
 */
public class RSemaphoreDemo {

	/**
	 * @param args
	 * @throws InterruptedException 
	 */
	public static void main(String[] args) throws InterruptedException {
		Config config = new Config();
		config
			//.setCodec(new FstCodec())
			.useSingleServer() //单例模式
			.setAddress("192.168.1.122:6379")//连接地址
			.setDatabase(1) // 数据库索引位置
			.setPassword("shijie99test") // 密码
			.setClientName("channelbatch") // 客户端名称
			;
		RedissonClient redisson = Redisson.create(config);
		
		RSemaphore semaphore = redisson.getSemaphore("semaphore");
		
		semaphore.acquire();
		
		semaphore.acquire(23);
		
		semaphore.tryAcquire();
		
		semaphore.tryAcquire(23, TimeUnit.SECONDS);
		
		semaphore.release(10);
		
		semaphore.release();
		
		redisson.shutdown();

	}

}
